package com.算法4.base;


import java.util.Arrays;

/**
 * @className: Test
 * @description: TODO 类描述
 * @author: YUANG
 * @date: 2022/2/9
 **/
public class Test {
    public static void main(String[] args) {
        //回文字符串
        String s = "abba";
        System.out.println(isPalindrome(s));

        //提取文件名和后缀\
        String[] baseAndExtension = getBaseAndExtension("hello.txt");
        System.out.println(Arrays.toString(baseAndExtension));

        //判断字符串是否已经排序
        String[] a = {"a", "b", "c", "a"};
        System.out.println(isSorted(a));

    }

    public static boolean isPalindrome(String s) {
        int n = s.length();
        for (int i = 0; i < n / 2; i++) {
            if (s.charAt(i) != s.charAt(n - 1 - i)) {
                return false;
            }
        }
        return true;
    }

    public static String[] getBaseAndExtension(String s) {
        int dot = s.indexOf(".");
        String base = s.substring(0, dot);
        String extension = s.substring(dot + 1);
        return new String[]{base, extension};
    }

    public static boolean isSorted(String[] a) {
        for (int i = 1; i < a.length; i++) {
            if (a[i - 1].compareTo(a[i]) > 0) {
                return false;
            }
        }
        return true;
    }
}
